﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.ApplyCommand;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.S.BaseData.Read.API.CommandHandler.ApplyHandler
{
    public class GetAppByHandler : IRequestHandler<GetAppByCommand, APIResult<List<User>>>
    {
        private readonly IBaseRepository<User> _baseRepository;

        public GetAppByHandler(IBaseRepository<User> baseRepository)
        {
            _baseRepository = baseRepository;
        }

        public async Task<APIResult<List<User>>> Handle(GetAppByCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<User>> result = new APIResult<List<User>>();
            result.Code = APIEnum.Success;
            result.Msg = "查询成功";

            var list = _baseRepository.GetAll().Where(p => p.Importance ==(request.Importance+1));

            result.Data = list.ToList();

            return await Task.FromResult(result);
        }
    }
}
